package com.zztl.infiniteBand.presenter

import android.content.Context
import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.BindedDeviceBean
import com.zztl.infiniteBand.model.NoDataResponseBean
import com.zztl.infiniteBand.net.FilterSubscriber
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.UnbindDeviceRequest
import com.zztl.infiniteBand.ui.view.mvpview.UnbindView

/**
 * @desc
 * @auth ${user}
 * @time 2018/9/27  10:25
 */
class MyDevicePresenter : BasePresenter<UnbindView>() {
    fun getBindDevice(context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.getBindDeviceList(""))
                .subscribe(object : FilterSubscriber<BindedDeviceBean>(context) {
                    override fun success(bean: BindedDeviceBean) {
                        view!!.getBindDeviceList(bean)
                    }

                }))
    }


    fun unBindDevice(imei: String, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.
                unBindDevice(DataConverter.instance.toJson(UnbindDeviceRequest(imei))))
                .subscribe(object : FilterSubscriber<NoDataResponseBean>(context) {
                    override fun success(deviceBean: NoDataResponseBean) {
                        view!!.unBindSuccess()
                    }

                    override fun fail() {
                        view!!.unBindFail()
                    }
                }))
    }

}
